package org.innovasix.educational.javap.domain.datatypes;

import org.innovasix.educational.javap.exception.InvalidArgumentException;

/**
 * Unsigned integer made up of 4 bytes
 * Range: From 0 to 4,294,967,295 which equals 2^32 - 1
 * 
 * @author sven.mentl@gmail.com
 *
 */
public class u4 {

	private int value;
	
	public u4(int highestByte, int secondHighestByte, int thirdHighestByte, int lowesByte){
		if(highestByte < 0 ||highestByte > 255) throw new InvalidArgumentException("highestByte " + highestByte + " is out of range.");
		if(secondHighestByte < 0 ||secondHighestByte > 255) throw new InvalidArgumentException("secondHighestByte " + secondHighestByte + " is out of range.");
		if(thirdHighestByte < 0 ||thirdHighestByte > 255) throw new InvalidArgumentException("thirdHighestByte " + thirdHighestByte + " is out of range.");
		if(lowesByte < 0 ||lowesByte > 255) throw new InvalidArgumentException("lowesByte " + lowesByte + " is out of range.");

		this.value = (highestByte << 24) + (secondHighestByte << 16) + (thirdHighestByte << 8) + lowesByte;
	}
	
	public int getValue() {
		return value;
	}
	
	public String toString(){

		return "0x" + LeadingZerosPadder.pad(8, value);
	}
}
